<?php
include_once '../../lib/config.php';
include_once '../../lib/db.php';
include '../../lib/utils/date.php';
include '../../lib/utils/tag.php';
include '../../model/departemen.php';
include '../../model/karyawan.php';
include '../../model/rangking.php';
include '../../model/perbuatan.php';
include '../../model/report.php';
include '../../model/report2.php';

$proc = $_REQUEST['proc'];

switch ($proc):
case 'graph':
	include ("../../lib/jpgraph/jpgraph.php");
	include ("../../lib/jpgraph/jpgraph_line.php");
	include ("../../lib/jpgraph/jpgraph_bar.php");
		
	//generate data
	$departemenID = $_REQUEST['departemenID'];
	$startPeriode = $_REQUEST['periode1'];
	$endPeriode = $_REQUEST['periode2'];
	if (!$startPeriode || !$endPeriode || !$departemenID) { return; }
	
	$achievBidang = is_array($achievBidang)? $achievBidang: array($achievBidang);
	
	$graphData = array();
	$CSIM = array();
	
	$REP_POINT_ALL=-1;
	$depCount = 0;
	foreach ( rep_rata_departemen2($departemenID, $startPeriode, $endPeriode) as $label=>$value){
		//label
		$graphData['label'][] = $label;
		
		// rata-rata departemen
		$graphData['pd'][] = $value;
		$CSIM['pd']['target'][] = "load_drillGraph(".json_encode(array(
				"type"=> '1',
				'departemenID'=> $departemenID[$depCount++],
				'startPeriode'=> $startPeriode,
				'endPeriode'=> $endPeriode,
			)).")";
		$CSIM['pd']['alt'][] = "%0.1f";
	}
	
	for ($i=0; $i<count($graphData['pd']); $i++){
		if ($REP_POINT_ALL<=0) $REP_POINT_ALL = rep_rata_seluruh_poin2($startPeriode, $endPeriode);
		
		$graphData['pa'][] = $REP_POINT_ALL;
		$CSIM['pa']['target'][] = "load_drillGraph(".json_encode(array(
				"type"=> '-1',
				'startPeriode'=> $startPeriode,
				'endPeriode'=> $endPeriode,
			)).")";
		$CSIM['pa']['alt'][] = "%0.1f";	
	}
	
	//create the bar plot, untuk data departemen
	$bplot1 = new BarPlot($graphData['pd']);
	$bplot1-> SetFillColor("blue");
	$bplot1->SetWidth(0.5);
	$bplot1->SetLegend('Rata-rata Total Point Departemen');
	$bplot1->SetCSIMTargets($CSIM['pd']['target'],$CSIM['pd']['alt']);
	$bplot1->value->Show();
	
	// Create the linear plot
	$line2 = __createLinePlot($graphData['pa'], 
		array('color'=>'red','weight'=>4), 
		array('type'=>MARK_SQUARE, 'fillColor'=>"red",'width'=>6),
		array('color'=>"darkred",'font'=>array(FF_FONT1, FS_BOLD)), 
		array('title'=>"Rata-rata Total Point Keseluruhan"),
		$CSIM['pa']);

	// Create the graph.
	$graph = new Graph(700,500,"auto");
	$graph->SetFrame(false,'white@.5',1); 
	$graph->title->Set("Total Point Perguruan Tinggi");
	$graph->SetColor("white");  	
	//$graph->SetScale("intlin");
	$graph->SetScale("textlin");
	$graph->img->SetMargin(80,30,40,80);
	$graph->img->SetAntiAliasing(); 
	
	$graph->ygrid->SetFill(true,'#FFFFFF@0.5','#d7e5f5@0.5');
	$graph->yaxis->SetFont(FF_FONT1,FS_BOLD);
	$graph->yaxis->SetPos("min");
	$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
	$graph->yaxis->title->set("Point");
	$graph->yaxis->SetTitleMargin(50);
	
	$graph->xaxis->SetFont(FF_FONT1,FS_BOLD);
	$graph->xaxis->SetPos("min");
	$graph->xaxis->SetTickLabels($graphData['label']);
	$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);
	$graph->xaxis->title->set("Periode");
	if ( count($graphData['label'])>10 ) {
		$graph ->xaxis->SetTextLabelInterval(count($graphData['label'])/4);
	}
	
	$graph->legend->SetLayout(LEGEND_HOR);
	$graph->legend->Pos(0.4,0.95,"center","bottom");
	
	// Add the plot to the graph
	$graph->Add($bplot1);	
	$graph->Add($line2);
	
	// Display the graph
	$graph->StrokeCSIM('proc/admin/totalPointUniversitas.php');
	break;
	
case 'graph-drill-departemen':
	$startPeriode = $_REQUEST['startPeriode'];
	$endPeriode = $_REQUEST['endPeriode'];
	$departemenID = $_REQUEST['departemenID'];
	include '../../view/admin/totalPointUniversitas/drill-departemen.php';
	break;
	
case 'graph-drill-all':
	$startPeriode = $_REQUEST['startPeriode'];
	$endPeriode = $_REQUEST['endPeriode'];
	include '../../view/admin/totalPointUniversitas/drill-all.php';
	break;
endswitch;